package com.kehutong.user.app;

import com.kehutong.common.util.Token;
import com.kehutong.contact.entity.ResidentCar;
import com.kehutong.contact.service.ResidentCarService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.util.Objects;

/**
 * 用户车辆
 * @author: liukunlong
 * @date: 2021-07-27 14:05
 */
@MvcAction
@ReqMapping("/kht-bin/crm/user/car")
public class UserCarAction {
    private static final Logger logger = LoggerFactory.getLogger(UserCarAction.class);
    @Inject
    private ResidentCarService residentCarService;
    /**
     * 用户车辆列表
     * @param jsonObject
     * @return
     * @throws Exception
     */
    @ReqMapping("/page")
    public Object page(Token token, JSONObject jsonObject) throws Exception {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        return residentCarService.list(jsonObject);
    }

    /**
     * 保存用户车辆信息
     * @param token
     * @param residentCar
     * @return
     * @throws Exception
     */
    @Bean(newInstance=true, copy=true)
    @ReqMapping("/save")
    public Object save(Token token,ResidentCar residentCar) throws Exception {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        residentCarService.save(residentCar);
        return Result.success();
    }


    /**
     * 更新用户车辆信息
     * @param token
     * @param residentCar
     * @return
     * @throws Exception
     */
    @Bean(copy = true)
    @ReqMapping("/update")
    public Object update(Token token,ResidentCar residentCar) throws Exception {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        residentCarService.update(residentCar);
        return Result.success();
    }

    /**
     * 删除用户车辆信息
     * @param token
     * @param residentCar
     * @return
     */
    @ReqMapping("/delete")
    public Object delete(Token token,ResidentCar residentCar) {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        residentCarService.delete(residentCar);
        return Result.success();
    }

}
